SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[usp_UpdateEmailSender]
	
	(
	  @param_id int,
	  @param_Admin_LoginID VARCHAR(50),
      @param_sender VARCHAR(50),
      @param_smtpaddress VARCHAR(50),
      @param_username VARCHAR(50),
      @param_password VARCHAR(50),
      @param_emailaddress VARCHAR(50),
      @param_is_default Bit,
      @param_update_time SmallDateTime,
      @param_user_update VARCHAR(50)
	)
	
AS
	/* SET NOCOUNT ON */
	 DECLARE @Count INT
                 SET @Count = (
                        SELECT   COUNT(*)
                        FROM     dbo.JOL_EmailManagement_Sender
                        WHERE    Admin_LoginID = @param_Admin_LoginID and id<>@param_id and emailaddress=@param_emailaddress
                        )
                IF @Count = 0 
                UPDATE  dbo.JOL_EmailManagement_Sender
                        set
                            
                             
                             sender=@param_sender,
                             smtpaddress=@param_smtpaddress,
                             username=@param_username,
                             password=@param_password,
                             emailaddress=@param_emailaddress,
                             is_default=@param_is_default,
                             update_time=@param_update_time,
                             user_update=@param_user_update
                             where
                             id=@param_id
                             
                             IF @param_is_default='TRUE'
						update dbo.JOL_EmailManagement_Sender 
						set 
							is_default='false'
							 where 
								Admin_LoginID=@param_Admin_LoginID and  is_default='TRUE' and emailaddress<>@param_emailaddress
                    
                   
                    
                ELSE
                        
                             
                           SELECT  '您未设置发件邮箱，不能修改，请转到添加页面'  
                   
	RETURN
GO
